<template>
	<view class="page_main page_render" :class="{ can_show: render_req }">
		<pagelogin ref="pagelogin" @loginready="pagerefresh" @initcallback="com_pagelogin_initcallback($event)">
			<!-- hasHeight :navstyle="{ background: '#1F1F1F' }" -->
			<diynav ref="diynav" :navstyle="{ background: '#383950' }" isFixed back hasHeight title="个人信息" @settop="set_pagetop($event)"></diynav>

			<myCardForm :showForm="page_show" :keyForm="page_form" v-if="render_req" @formChange="formChange"></myCardForm>
		</pagelogin>
	</view>
</template>

<script>
import pagelogin from '@/components/pagelogin/pagelogin';
export default {
	components: {
		pagelogin,
	},
	data() {
		return {
			scrollTop: 0,
			page_render: false,
			render_req: false,
			page_form: {
				user_sex: '',
				user_age: '',
			},
			nextreq: true,
			page_show: [
				{
					views_name: '',
					views: [
						{
							title: '我的头像',
							formtype: 'upload',
							state: 'edit',
							key: 'user_head',
						},
						{
							title: '昵称',
							placeholder: '请输入您的昵称',
							formtype: 'text',
							state: 'edit',
							key: 'nickname',
							// regular: 'name',
							inptype: 'text',
						},
						{
							title: '性别',
							formtype: 'text',
							state: 'disable',
							key: 'user_sex',
						},
						{
							title: '生日',
							formtype: 'text',
							state: 'disable',
							key: 'user_age',
						},
					],
				},
			],
		};
	},
	onLoad() {
		this.init_pagedata('user_set_info', this);
	},
	onShow() {},
	methods: {
		formChange(e) {
			console.log(e);
			let _this = this;

			let { value, key } = e;
			// debugger
			if (this.page_form[key] == value) return;

			let url_obj = {
				user_head: '/user/head',
				nickname: '/user/nickname',
			};
			let data, data_handle_on;

			let user_id = uni.getStorageSync('userid');

			if (!_this.com_loading({ status: 1, title: '修改中...' })) return;

			if (key == 'user_head') {
				// 设置头像
				data = {
					user_id,
					user_head: value,
				};
				data_handle_on = false;
			} else {
				// 设置昵称等其他
				data = {
					id: user_id,
					name: value,
				};
				data_handle_on = true;
			}

			_this.com_getdata({
				url: url_obj[key],
				data_handle_on,
				data,
				export_name: 'page_form',
				data_fun: function (v) {
					// console.log(JSON.stringify(v), 'go_sign')
					_this.com_loading({ status: 0 });
					if (v.state == 1) {
						_this.page_form[key] = value;
						_this.com_msg(v.msg);
					} else {
						_this.com_msg(v.msg || '网络请求错误');
					}
				},
			});
		},
		pagerefresh(type = 0) {
			let _this = this;
			_this.com_page_show(_this);
			if (_this.loginJudge() == 1) {
				let user_id = uni.getStorageSync('userid');
				_this.com_getdata({
					url: '/user/info',
					data: {
						user_id,
					},
					get_export_name: 'info',
					export_name: 'page_form',
					data_fun: function () {
						if (!_this.page_form.user_sex) {
							_this.page_form.user_sex = '无';
						}
						if (!_this.page_form.user_age) {
							_this.page_form.user_age = '无';
						}
					},
				});
			}

			setTimeout(() => {
				_this.render_req = true;
			}, 100);
		},
	},
	watch: {},
};
</script>

<style lang="scss">
.msg_set_con {
	padding: 30rpx;

	.msg_view {
		// height: 126rpx;
		padding: 20rpx;
		background: #ffffff;
		border-radius: 20rpx;

		// &+.msg_view {
		// 	margin-top: 20rpx;
		// }

		.msg_top {
			display: flex;
			justify-content: space-between;
			align-items: center;
		}

		.tt {
			font-size: 32rpx;
			font-weight: bold;
			color: #2e3443;
		}

		.tips {
			margin-top: 10rpx;
			font-size: 20rpx;
			// font-weight: bold;
			color: #999999;
		}
	}
}

.delete_msg {
	height: 98rpx;
	background: #ffffff;
	border-radius: 20rpx;

	font-size: 32rpx;
	font-weight: 500;
	color: #e30000;
	display: flex;
	align-items: center;
	justify-content: center;
}
</style>
